//CameraEvents are Events caused by the camera and propagated to the driver/client in some way. Extend if needed but please coordinate...
typedef enum CameraEvent {
CameraEventSnapshotButtonDown,
CameraEventSnapshotButtonUp,
} CameraEvent;
//CameraFeatures are custom feeatures of the camera
typedef enum CameraFeature {
CameraFeatureInspectorClassName //A NSString containing the name of a MyCameraInspector subclass. Read-only.
} CameraFeature;
@interface MyCameraDriver : NSObject {
//General stuff
id delegate; //The delegate to notify [imageReady], [grabFinished] and [cameraHasShutDown].
id central; //The central singleton to indicate [cameraHasShutDown].
//usb connection camera interfaces
IOUSBDeviceInterface** dev; //An interface to the device
IOUSBInterfaceInterface** intf; //An interface to the interface
//Camera settings.
float brightness;
float contrast;
float saturation;
float gamma;
float sharpness;
float shutter;
float gain;
BOOL autoGain;
BOOL hFlip;
CameraResolution resolution;
WhiteBalanceMode whiteBalanceMode;
BOOL blackWhiteMode; // is color or Black and White (greyscale)
BOOL LEDon; // is the LED on or off (Philips cameras)
short fps;
short compression; //0 = uncompressed, higher means more compressed
//Driver states. Sorry, this has changed - the old version was too sensible to racing conditions. Everything except atomic read access has to be mutexed with stateLock (there is an exception: drivers may unset shouldBeGrabbing from within their internal grabbing and decoding since it's for sure that isGrabbing is set in that situation)
BOOL isStarted; //If the driver has been started up
BOOL isGrabbing; //If the driver is in grabbing state
BOOL shouldBeGrabbing; //If the grabbing thread should stop running
BOOL isShuttingDown; //If the driver is shutting down and shouldn't accept new grabbing requests
BOOL isShutDown; //If the driver has already been down
BOOL isUSBOK; //If USB calls to intf and dev are ok. Unset without lock to be as fast as possible
NSLock* stateLock; //The Lock to mutex all of this stuff
/* Stuff for merging notifications. Init these if you want to use the merging notification forwarders and the client wants notifications on the main thread. This is a good candidate for refacturing... */
BOOL doNotificationsOnMainThread; //If the client wants main thread calls or accepts other thread notifications
NSRunLoop* mainThreadRunLoop;
NSConnection* mainThreadConnection;
NSConnection* decodingThreadConnection;
/*
Image buffers. There are two sets: lastIamgeBuffer and nextImageBuffer. The client writes the next buffer to fill into nextImageBuffer via [setImageBuffer]. This also sets nextImageBufferSet to true, indicating the driver that image data may be written into it. The driver then writes the next available image into this buffer, copies the properties into lastImageBuffer and unsets nextImageBuffer. The read functions for the client may then read out lastImageBuffer. There is a lock to manage the access to these variables, imageBufferLock. The get functions don't use the lock since they don't change anything. They are only guaranteed to be valid during the [imageReady] notification. Setting nextImageBuffer is locked during the whole procedure of decoding the image.
*/
unsigned char* lastImageBuffer;
short lastImageBufferBPP;
long lastImageBufferRowBytes;
unsigned char* nextImageBuffer;
short nextImageBufferBPP;
long nextImageBufferRowBytes;
BOOL nextImageBufferSet;
NSLock* imageBufferLock;
MyCameraInfo* cameraInfo;
}
//Get info about the camera specifics - simple mechanism
+ (unsigned short) cameraUsbProductID;
+ (unsigned short) cameraUsbVendorID;
+ (NSString*) cameraName;
//Get info - new mechanism. Overload this one if you have more than one idVendor/idProduct pair
+ (NSArray*) cameraUsbDescriptions;
//Should return an array of dictionaries with keys "idVendor" (NSNumber), "idProduct" (NSNumber) and "name" (NSString). The default implementation creates an array with one entry with values of the above methods.
/*Note that "notifications" here are not exactly Cocoa notifications. They are delegate methods (the delegate concept matches a bit better to the Cocoa counterpart). But they also notify... */
//Merged Notification forwarders - should be used for notifications from decodingThread